package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbMasterEnter;
import com.ruoyi.wb.service.IWbMasterEnterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 师傅入驻Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@Api(tags="师傅入驻信息管理")
@RestController
@RequestMapping("/wb/wbMasterEnter")
public class WbMasterEnterController extends BaseController {
    @Autowired
    private IWbMasterEnterService wbMasterEnterService;


    /**
     * 查询师傅入驻列表
     */
    @ApiOperation("查询师傅入驻列表")
    @GetMapping("/list")
    public TableDataInfo list(WbMasterEnter wbMasterEnter) {

        startPage();
        List<WbMasterEnter> list = wbMasterEnterService.selectWbMasterEnterList(wbMasterEnter);
        return getDataTable(list);
    }

    /**
     * 导出师傅入驻列表
     */
    @ApiOperation("导出师傅入驻列表")
    @Log(title = "师傅入驻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbMasterEnter wbMasterEnter) {
        List<WbMasterEnter> list = wbMasterEnterService.selectWbMasterEnterList(wbMasterEnter);
        ExcelUtil<WbMasterEnter> util = new ExcelUtil<WbMasterEnter>(WbMasterEnter.class);
        util.exportExcel(response, list, "师傅入驻数据");
    }

    /**
     * 获取师傅入驻详细信息
     */
    @ApiOperation("获取师傅入驻详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wbMasterEnterService.selectWbMasterEnterById(id));
    }

    /**
     * 新增师傅入驻
     */
    @ApiOperation("新增师傅入驻")
    @Log(title = "师傅入驻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbMasterEnter wbMasterEnter) {
        int i = wbMasterEnterService.insertWbMasterEnter(wbMasterEnter);
        if (i==0){
        throw new RuntimeException("已经入驻无法再次新增");
        }

        return toAjax(i);
    }

    /**
     * 修改师傅入驻
     */
    @ApiOperation("修改师傅入驻")
    @Log(title = "师傅入驻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbMasterEnter wbMasterEnter) {
        return toAjax(wbMasterEnterService.updateWbMasterEnter(wbMasterEnter));
    }

    /**
     * 删除师傅入驻
     */
    @ApiOperation("删除师傅入驻")
    @Log(title = "师傅入驻", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wbMasterEnterService.deleteWbMasterEnterByIds(ids));
    }

    /**
     * 审核师傅入驻
     */
    @ApiOperation("审核师傅入驻")
    @Log(title = "师傅入驻", businessType = BusinessType.OTHER)
    @PutMapping(value = "/audit/{id}")
    public AjaxResult audit(@PathVariable("id") Long id, HttpServletRequest request) {
        return toAjax(wbMasterEnterService.auditWbMasterEnter(id));
    }


    /**
     *  获取师傅入驻详细信息
     */
    @ApiOperation("获取师傅入驻详细信息")
    @GetMapping(value = "/byUser")
    public AjaxResult byUser() {
        return success(wbMasterEnterService.byUser());
    }


    /**
     * 根据当前用户返回师傅
     */
    @GetMapping("/acquiringMaster")
    public AjaxResult acquiringMaster() {

        return wbMasterEnterService.acquiringMaster();
    }
}